<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <div style="text-align: center">
        <a-button @click="handleCancel" style="background: #5c6065;color: white"> 返回</a-button>
      </div>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="教师名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="roleDisabled" v-decorator="[ 'addusername', validatorRules.addusername]" placeholder="请输入记录人姓名"></a-input>
        </a-form-item>
        <a-form-item label="总结类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="roleDisabled" v-decorator="[ 'gzzjlxid', validatorRules.gzzjlxid]" placeholder="请输入工作总结类型code"></a-input>
        </a-form-item>
        <a-form-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="roleDisabled" v-decorator="[ 'gzzjbt', validatorRules.gzzjbt]" placeholder="请输入工作总结标题"></a-input>
        </a-form-item>
        <a-form-item label="内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number :disabled="roleDisabled" v-decorator="[ 'gzzjtid', validatorRules.gzzjtid]" placeholder="请输入工作总结内容（大文本字段ID）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="日志时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择日志时间" :disabled="roleDisabled" v-decorator="[ 'gzzjrq', validatorRules.gzzjrq]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="评审人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="roleDisabled" v-decorator="[ 'verifyusername', validatorRules.verifyusername]" placeholder=""></a-input>
        </a-form-item>
        <a-form-item label="评审时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" :disabled="roleDisabled" v-decorator="[ 'verifytime', validatorRules.verifytime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="评审量值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number :disabled="roleDisabled" v-decorator="[ 'verifyresult', validatorRules.verifyresult]" placeholder="" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="评审说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input :disabled="roleDisabled" v-decorator="[ 'verifytid', validatorRules.verifytid]" placeholder="" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>


</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/edu/JDate'

  export default {
    name: "VeJwGzzjModal",
    components: {
      JDate
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"查看工作总结",
        width:800,
        visible: false,
        roleDisabled: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          adduser: {rules: [
              {required: true, message: '请输入记录人（教师）ID!'},
            ]},
          addusername: {rules: [
            ]},
          jsgh: {rules: [
              {required: true, message: '请输入教师工号!'},
            ]},
          gzzjlxid: {rules: [
              {required: true, message: '请输入工作总结类型code!'},
            ]},
          gzzjbt: {rules: [
              {required: true, message: '请输入工作总结标题!'},
            ]},
          gzzjtid: {rules: [
              {required: true, message: '请输入工作总结内容（大文本字段ID）!'},
            ]},
          gzzjrq: {rules: [
              {required: true, message: '请输入工作总结日期（时间）!'},
            ]},
          status: {rules: [
              {required: true, message: '请输入状态：1=完成，0=草稿!'},
            ]},
          verifyuser: {rules: [
            ]},
          verifyusername: {rules: [
            ]},
          verifyresult: {rules: [
            ]},
          verifytime: {rules: [
            ]},
          verifytid: {rules: [
            ]},
          terminalid: {rules: [
              {required: true, message: '请输入终端ID!'},
            ]},
        },
        url: {
          add: "/teacherWork/veJwGzzj/add",
          edit: "/teacherWork/veJwGzzj/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        //编辑页面禁止修改角色编码
        if(this.model.id){
          this.roleDisabled = true;
        }else{
          this.roleDisabled = false;
        }
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'adduser','addusername','jsgh','gzzjlxid','gzzjbt','gzzjtid','gzzjrq','status','verifyuser','verifyusername','verifyresult','verifytime','verifytid','terminalid'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                that.close();
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'adduser','addusername','jsgh','gzzjlxid','gzzjbt','gzzjtid','gzzjrq','status','verifyuser','verifyusername','verifyresult','verifytime','verifytid','terminalid'))
      },


    }
  }
</script>